#!/usr/bin/env python3
#coding:utf-8

__author__ = 'xmxoxo<xmxoxo@qq.com>'

'''
rabbitmq 演示程序，可带入参数演示不同场景; 

'''

import argparse
import os
import sys
import time
import sys
import subprocess
from multiprocessing import Process

parser = argparse.ArgumentParser(description='演示')
parser.add_argument('--scene', type=int, required=1, default=1, help='演示的类型')
args = parser.parse_args()

def runcmd(sCmd):
    strCmd = "start python.exe %s" % sCmd
    #pro = subprocess.Popen(strCmd)
    os.system(strCmd)
    time.sleep(2)

def batch_run(cmd_list:str):
    ''' 批量启动命令行
    '''
    for tcmd in cmd_list:
        runcmd(tcmd)
    

def RunDemo(args):
    scene = args.scene
    cmd_list = []
    if scene==1:
        # 场景1:单个生产者数据上传, 单个消费者收发消息
        print('正在启动： 场景1:单个生产者数据上传, 单个消费者收发消息')
        cmd_list = [
                    "mq_receive.py --channel=fj.xm.*"
                    "mq_sender.py",
                   ]

    if scene==2:
        # 场景2:单个生产者数据上传，多个消费者消息订阅
        print('正在启动：场景2:单个生产者数据上传，多个消费者消息订阅')
        cmd_list = [
                    "mq_receive.py --channel=fj.xm.*",
                    "mq_receive.py --channel=fj.fz.*",
                    "mq_sender.py",
                   ]
    if scene==3:
        # 场景3:多点生产者数据上传，多个消费者消息订阅；
        print('正在启动：场景3:多点生产者数据上传，多个消费者消息订阅')
        cmd_list = [
                    "mq_receive.py --channel=fj.*.*",
                    "mq_receive.py --channel=fj.fz.*",
                    "mq_sender.py --channel=fj.xm.231",
                    "mq_sender.py --channel=fj.fz.137",
                   ]

    if scene==4:
        # 场景4: 消息仅限单次消费。多点生产者数据上传，多个消费者订阅同频道消息；
        print('正在启动：消息仅限单次消费。多点生产者数据上传，多个消费者订阅同频道消息')
        cmd_list = [
                    # 启动两个消费者
                    "mq_receive.py --channel=fj.xm.*", 
                    "mq_receive.py --channel=fj.xm.*",
                    # 启动两个生产者, 其中231的消息只允许 单次消费
                    "mq_sender.py --channel=fj.xm.231 --repeat=0", # --repeat=0
                    "mq_sender.py --channel=fj.xm.137",
                   ]

    batch_run (cmd_list)
    


if __name__ == '__main__':
    pass
    RunDemo(args)
